#include "main.h"

#define GAPY 27
#define GAPX 15
#define AB 97


class font
{
	private:
		SDL_Surface *temp;
		vector <SDL_Surface*> fontti;
		
		SDL_Rect src;
		SDL_Rect dst;
	public:
		font();
		void text(string teksti);
		void draw(int y, int x, int fonttike);
		
		void flush(int);
		
		SDL_Surface* return_surface();
};

font::font()
{
	temp = IMG_Load("font.png");
	fontti.push_back(temp);
	
	
}

void font::text(string teksti)
{
	src.x = 0;
	src.w = 60;
	
	dst.y = 0;
	dst.h = 0;
	
	temp = SDL_CreateRGBSurface(SDL_SWSURFACE, teksti.length()*GAPX, 15, 32, 0, 0, 0, 0);
	for (int i = 0; i < teksti.length(); i++)
	{
		src.y = (teksti[i] - AB) * GAPY;
		src.h = src.y + GAPY;
		
		dst.x = i*GAPX;
		dst.w = dst.x + GAPX;
		
		SDL_BlitSurface(fontti[0], &src, temp, &dst);
	}
	
	
	SDL_SetColorKey( temp, SDL_SRCCOLORKEY, SDL_MapRGB(temp->format,0,0,0));

	fontti.push_back(temp);
}

void font::draw(int x, int y, int fonttike)
{
	dst.x = x;
	dst.y = y;
	SDL_BlitSurface(fontti[fonttike], NULL, screen, &dst);
}

void font::flush(int valinta)
{
	if (valinta == 69)
		for (int i = 1; i < fontti.size(); i++)
			SDL_FreeSurface(fontti[i]);
	else
		SDL_FreeSurface(fontti[valinta]);
	if (temp)
		SDL_FreeSurface(temp);
}















/* 
	if (SDL_GetTicks()-beginning > 3500)
	{
	if (beginning2 == 0)
		beginning2 = SDL_GetTicks()-1;
	
	src.x = 320 - ((SDL_GetTicks()-beginning2)/20.);
	src.y = 240 - ((SDL_GetTicks()-beginning2)/20.);
	src.w = ((SDL_GetTicks()-beginning2)/10.);
	src.h = ((SDL_GetTicks()-beginning2)/10.);
	
	dst.x = 320 - ((SDL_GetTicks()-beginning2)/20.);
	dst.y = 240 - ((SDL_GetTicks()-beginning2)/20.);
	
	cout<<src.x<<"\n"<<src.y<<"\n"<<src.w<<"\n"<<src.h<<"\n"<<dst.x<<"\n"<<dst.y<<"\n"<<beginning2<<"\n";
		
	SDL_BlitSurface(kuvat[4].surface, &src, screen, &dst);
	}*/
